<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Token count datatype | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'token-count.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/token-count.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/token-count.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/token-count.html" rel="nofollow" target="_blank">../en/token-count.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="mapping.html">Mapping</a></span>
»
<span class="breadcrumb-link"><a href="mapping-types.html">Field datatypes</a></span>
»
<span class="breadcrumb-node">Token count datatype</span>
</div>
<div class="navheader">
<span class="prev">
<a href="text.html">« Text datatype</a>
</span>
<span class="next">
<a href="shape.html">Shape datatype »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="token-count"></a>Token count datatype<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/mapping/types/token-count.asciidoc">edit</a>
</h2>
</div></div></div>

<p>A field of type <code class="literal">token_count</code> is really an <a class="xref" href="number.html" title="Numeric datatypes"><code class="literal">integer</code></a> field which
accepts string values, analyzes them, then indexes the number of tokens in the
string.</p>
<p>For instance:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT my_index
{
  "mappings": {
    "properties": {
      "name": { <a id="CO322-1"></a><i class="conum" data-value="1"></i>
        "type": "text",
        "fields": {
          "length": { <a id="CO322-2"></a><i class="conum" data-value="2"></i>
            "type":     "token_count",
            "analyzer": "standard"
          }
        }
      }
    }
  }
}

PUT my_index/_doc/1
{ "name": "John Smith" }

PUT my_index/_doc/2
{ "name": "Rachel Alice Williams" }

GET my_index/_search
{
  "query": {
    "term": {
      "name.length": 3 <a id="CO322-3"></a><i class="conum" data-value="3"></i>
    }
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/705.console"></div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO322-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>The <code class="literal">name</code> field is a <a class="xref" href="text.html" title="Text datatype"><code class="literal">text</code></a> field which uses the default
<code class="literal">standard</code> analyzer.</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO322-2"><i class="conum" data-value="2"></i></a></p>
</td>
<td align="left" valign="top">
<p>The <code class="literal">name.length</code> field is a <code class="literal">token_count</code> <a class="xref" href="multi-fields.html" title="fields">multi-field</a> which will index the number of tokens in the <code class="literal">name</code> field.</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO322-3"><i class="conum" data-value="3"></i></a></p>
</td>
<td align="left" valign="top">
<p>This query matches only the document containing <code class="literal">Rachel Alice Williams</code>, as it contains three tokens.</p>
</td>
</tr>
</table>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="token-count-params"></a>Parameters for <code class="literal">token_count</code> fields<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/mapping/types/token-count.asciidoc">edit</a>
</h3>
</div></div></div>
<p>The following parameters are accepted by <code class="literal">token_count</code> fields:</p>
<div class="informaltable">
<table border="0" cellpadding="4px">
<colgroup>
<col>
<col>
</colgroup>
<tbody valign="top">
<tr>
<td valign="top">
<p>
<a class="xref" href="analyzer.html" title="analyzer"><code class="literal">analyzer</code></a>
</p>
</td>
<td valign="top">
<p>
The <a class="xref" href="analysis.html" title="Text analysis">analyzer</a> which should be used to analyze the string
value. Required. For best performance, use an analyzer without token
filters.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
<code class="literal">enable_position_increments</code>
</p>
</td>
<td valign="top">
<p>
Indicates if position increments should be counted.
Set to <code class="literal">false</code> if you don’t want to count tokens removed by analyzer filters (like <a class="xref" href="analysis-stop-tokenfilter.html" title="Stop token filter"><code class="literal">stop</code></a>).
Defaults to <code class="literal">true</code>.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
<a class="xref" href="mapping-boost.html" title="boost"><code class="literal">boost</code></a>
</p>
</td>
<td valign="top">
<p>
Mapping field-level query time boosting. Accepts a floating point number, defaults
to <code class="literal">1.0</code>.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
<a class="xref" href="doc-values.html" title="doc_values"><code class="literal">doc_values</code></a>
</p>
</td>
<td valign="top">
<p>
Should the field be stored on disk in a column-stride fashion, so that it
can later be used for sorting, aggregations, or scripting? Accepts <code class="literal">true</code>
(default) or <code class="literal">false</code>.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
<a class="xref" href="mapping-index.html" title="index"><code class="literal">index</code></a>
</p>
</td>
<td valign="top">
<p>
Should the field be searchable? Accepts <code class="literal">true</code> (default) and <code class="literal">false</code>.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
<a class="xref" href="null-value.html" title="null_value"><code class="literal">null_value</code></a>
</p>
</td>
<td valign="top">
<p>
Accepts a numeric value of the same <code class="literal">type</code> as the field which is
substituted for any explicit <code class="literal">null</code> values.  Defaults to <code class="literal">null</code>, which
means the field is treated as missing.
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
<a class="xref" href="mapping-store.html" title="store"><code class="literal">store</code></a>
</p>
</td>
<td valign="top">
<p>
Whether the field value should be stored and retrievable separately from
the <a class="xref" href="mapping-source-field.html" title="_source field"><code class="literal">_source</code></a> field. Accepts <code class="literal">true</code> or <code class="literal">false</code>
(default).
</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>

</div>
<div class="navfooter">
<span class="prev">
<a href="text.html">« Text datatype</a>
</span>
<span class="next">
<a href="shape.html">Shape datatype »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>